package com.lnsystem.dao;

import java.math.BigInteger;
import java.util.List;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;

import com.lnsystem.model.Stock;
import com.lnsystem.model.StockDailyData;
import com.lnsystem.model.StockRating;
import com.lnsystem.model.StockWeeklyData;

public interface StockDao {
        
        List<Stock> getAllStocks();
        List<Stock> getStocksOverCertainVolume(double volume);
        List<Stock> getStocksOverCertainPriceVolume(double price, double volume);
        List<Stock> getStocksByPriceRangeOverCertainVolume(double minPrice, double maxPrice, double volume);

        Stock getStockById(int id);
        Stock getStockBySymbol(String symbol);

        int addStock(Stock stock);
        int updateStock(Stock stock);

        /**
         * Gets all stock daily data for a stock.
         * @param s - the stock 
         */
        List<StockDailyData> getStockDailyData(Stock s, boolean sortDesc);
        
        
        /**
         * Gets all stock daily data between two dates.
         * @param s - the stock 
         * @param startDate - all dailydata records to be fetched from this date.
         * @param endDate - all dailydata records to be fetched to this date.
         */
        List<StockDailyData> getStockDailyData(Stock s, LocalDate startDate, LocalDate endDate,boolean sortDesc);
        /**
         * Gets all stock daily data before a certain date.
         * @param s - the stock 
         * @param date - all dailydata records to be fetched up to this date.
         */
        List<StockDailyData> getStockDailyDataBeforeDate(Stock s, LocalDate date,boolean sortDesc);

        /**
         * Gets all stock daily data after a certain date.
         * @param s - the stock 
         * @param date - all dailydata records to be fetched up to this date.
         */
        List<StockDailyData> getStockDailyDataAfterDate(Stock s, LocalDate date,boolean sortDesc);

        /**
         * Gets dailydata for the given date for a specific stock (symbol).
         * @param symbol - the stock symbol
         * @param date - the date
         */
        StockDailyData getStockDailyData(String symbol, LocalDate date);
        
        /**
         * Gets the most recent dailydata record for a stock.
         * @param s - the stock 
         */
        StockDailyData getMostRecentDailyData(Stock s);
        
        /**
         * Gets the most recent close price for a stock.
         * @param s - the stock 
         */
		double getMostRecentClose(Stock s);
        
        BigInteger getAverageVolume(Stock s);
        
        BigInteger getAverageVolume(Stock s, int days);
        
        /**
         * Gets the maximum volume on down days (red days) in the last 10 days of dailyData's date.
         * @param dailyData - the stock dailydata
         */
		BigInteger getMaxDownDayVolume(StockDailyData dailyData);

        
        double getSMA(StockDailyData sd, int period);
        double getEMA(StockDailyData sd, int period);
        
        
        /**
         * Gets all stock weekly data for a stock.
         * @param s - the stock 
         */
        List<StockWeeklyData> getStockWeeklyData(Stock s);
        
        /**
         * Gets all stock weekly data between two dates.
         * @param s - the stock 
         * @param startDate - all dailydata records to be fetched from this date.
         * @param endDate - all dailydata records to be fetched to this date.
         */
        List<StockWeeklyData> getStockWeeklyData(Stock s, LocalDate startDate, LocalDate endDate);
        /**
         * Gets all stock weekly data before a certain date.
         * @param s - the stock 
         * @param date - all dailydata records to be fetched up to this date.
         */
        List<StockWeeklyData> getStockWeeklyDataBeforeDate(Stock s, LocalDate date);

        /**
         * Gets all stock weekly data after a certain date.
         * @param s - the stock 
         * @param date - all dailydata records to be fetched up to this date.
         */
        List<StockWeeklyData> getStockWeeklyDataAfterDate(Stock s, LocalDate date);

        
        /**
         * Gets the most recent weekly data record for a stock.
         * @param s - the stock 
         */
        StockWeeklyData getMostRecentWeeklyData(Stock s);

	
        /**
         * Flushes & clears the session
         */
		void flushAndClear();
		
        /**
         * add or update the stockrating data
         * @param stockRating - the stockRating data
         */
		int updateStockRatingData(StockRating stockRating);
		
		
        /**
         * gets high for pivot calculation...
         * @param s - the stock
         * @param datetime - the datetime to be used for finding high/low/close for pivot calculation
         * @param timeFrame - daily/weekly/monthy/intraday
         */
		double getHighForPivotCalculation(Stock s, DateTime dateTime, int timeFrame);
		
        /**
         * gets low for pivot calculation...
         * @param s - the stock
         * @param datetime - the datetime to be used for finding high/low/close for pivot calculation
         * @param timeFrame - daily/weekly/monthy/intraday
         */
		double getLowForPivotCalculation(Stock s,DateTime dateTime, int timeFrame);
		
        /**
         * gets close for pivot calculation...
         * @param s - the stock
         * @param datetime - the datetime to be used for finding high/low/close for pivot calculation
         * @param timeFrame - daily/weekly/monthy/intraday
         */
		double getCloseForPivotCalculation(Stock s, DateTime dateTime, int timeFrame);

      
}